package com.soul.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.soul.common.msg.ApiResult;
import com.soul.sys.bean.dto.user.UserAddDto;
import com.soul.sys.bean.dto.user.UserSearchDto;
import com.soul.sys.bean.dto.user.UserUpdateDto;
import com.soul.common.bean.vo.UserVo;
import com.soul.sys.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("user")
@Api(value="user", tags = "用户模块接口")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{id}/info")
    public ApiResult<UserVo> getInfo(@PathVariable("id") Long id){
        UserVo userVo = userService.getInfoById(id);
        return ApiResult.success(userVo);
    }


    @GetMapping("/{page}/{size}/list")
    public ApiResult<IPage<UserVo>> queryUserList(@PathVariable("page") Integer page, @PathVariable("size") Integer size, UserSearchDto searchDto){
        IPage<UserVo> userVoIPage = this.userService.queryUserList(page, size, searchDto);
        return ApiResult.success(userVoIPage);
    }



    @PostMapping("/add")
    public ApiResult<Void> addUser(@RequestBody UserAddDto addDto){
        this.userService.addUser(addDto);
        return ApiResult.success();
    }


    @PutMapping("/update")
    public ApiResult<Void> updateUser(@RequestBody UserUpdateDto updateDto){
        this.userService.updateUser(updateDto);
        return ApiResult.success();
    }

    @DeleteMapping("/delete")
    public ApiResult<Void> deleteUser(@RequestBody List<Long> ids){
        this.userService.delUser(ids);
        return ApiResult.success();
    }


    @PostMapping("/query/ids")
    public ApiResult<List<UserVo>> queryUserVoByIds(@RequestBody Collection<Long> ids){
        List<UserVo> userVos = this.userService.queryUserByIds(ids);
        return ApiResult.success(userVos);
    }

}
